<?php

namespace app\index\controller;

use tian\Session;

class Monster extends Base
{
    public function info()
    {
        try {
            $role_id = Session::get('uid');

            $id = input('id');
            $info = model('MapMonster')->getInfo($id);
            if (!empty($info)) {
                if($info['type']==1){
                    $infoMonster = model('Monster')->getInfo($info['gyid']);

                    $info['gzb_list'] = $this->strSelect($infoMonster['gzb'],1);
                    $info['gdj_list'] = $this->strSelect($infoMonster['gdj'],2);
                    $info['gyp_list'] = $this->strSelect($infoMonster['gyp'],3);
                }
                if($info['type']==2){
                    $infoMonster = model('Boss')->getInfo($info['gyid']);

                    $info['gzb_list'] = $this->strSelect($infoMonster['bosszb'],1);
                    $info['gdj_list'] = $this->strSelect($infoMonster['bossdj'],2);
                    $info['gyp_list'] = [];
                }
            }
            $this->assign('info', $info);
            //echo "<pre>";print_r($info);die;

            $str = str_base64_encode($id,$role_id);
            $this->assign('str', $str);

            $this->fetch('info');
        } catch (\Throwable $e) {
            echo $e->getMessage();
        }
    }

    public function strSelect($strIds,$type): array
    {
        $ary = ($strIds != '' && $strIds != null) ? explode(',', $strIds) : [];
        $list = [];
        if (!empty($ary)) {
            foreach ($ary as $k => $item) {
                $name = '';
                if($type==1){
                    $name = model('Equip')->findValue(['zbid'=>$item],'zbname');
                    $list[$k]['lv'] = model('Equip')->findValue(['zbid'=>$item],'zblv');
                }
                if($type==2){
                    $name = model('Prop')->findValue(['djid'=>$item],'djname');
                }
                if($type==3){
                    $name = model('Drug')->findValue(['ypid'=>$item],'ypname');
                    $list[$k]['lv'] = model('Drug')->findValue(['ypid'=>$item],'yplv');
                }
                $list[$k]['id'] = $item;
                $list[$k]['name'] = $name;
            }
        }
        return $list;
    }


}
